package com.ld.admin.controller.webbot;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ld.admin.controller.AdminBasicController;
import com.ld.admin.model.webbot.WebBotModel;
import com.ld.admin.service.webbot.WebBotService;
import com.ld.shieldsb.common.core.model.Result;
import com.ld.shieldsb.common.web.util.Web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * 聊天机器人
 * 
 * @ClassName WebBotController
 * @author <a href="mailto:donggongai@126.com" target="_blank">吕凯</a>
 * @date 2019年08月28日 16:32:08
 *
 */
@Api(tags = "聊天机器人")
@ConditionalOnProperty(prefix = "modules.sc.webbot", name = "enable", havingValue = "true", matchIfMissing = true)
@Controller(value = "WebBotController")
@RequestMapping("${shieldsb.adminPath}/webbot")
public class WebBotController extends AdminBasicController<WebBotModel> {
    @Autowired
    protected WebBotService webBotService;

    @ApiOperation(value = "首页", notes = "")
    @RequestMapping(path = "", method = RequestMethod.GET)
    public String index() {
        return "a/webbot/webbot_header";
    }

    @ApiOperation(value = "到搜索页面", notes = "")
    @RequestMapping(path = "/toSearch", method = RequestMethod.GET)
    public String toSearch() {
        setAttributes();
        return "a/webbot/webbot_search";
    }

    @ApiOperation(value = "发送消息", notes = "")
    @RequestMapping(path = "/send", method = RequestMethod.POST)
    // 返回json格式
    @ResponseBody
    public Object send(WebBotModel model) {
        Result result = webBotService.send(getInt("type"), getString("content"), "");
        return Web.Response.resultWithData(result);
    }

}